﻿---创建最新水情视图
IF OBJECT_ID ('NewlyReportView', 'view') IS NOT NULL
DROP VIEW NewlyReportView
GO

CREATE VIEW NewlyReportView
AS
SELECT SW.st_code, ST.st_name, ST.unit_code, SW.dt, SW.w_flow, SW.w_level
FROM 
(
	SELECT *, ROW_NUMBER() OVER( PARTITION BY st_code ORDER BY dt DESC ) AS RowIndex
	FROM st_water 
) SW
INNER JOIN t_st ST
ON SW.st_code = ST.st_code
WHERE SW.RowIndex = 1
